package com.javafamily.controller;

import com.javafamily.bean.Pets;
import com.javafamily.service.PetsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//提供者Controller，对外提供接口
@RequestMapping("/provider/pets")
@RestController
public class PetsController {
    @Autowired
    private PetsService service;

    // 新增
    @PostMapping("/save")
    public boolean saveHandle(@RequestBody Pets pets) {
        return service.savePets(pets);
    }

    // 删除
    @DeleteMapping("/del/{id}")
    public boolean deleteHandle(@PathVariable("id") int id) {
        return service.removePetsById(id);
    }

    // 修改
    @PutMapping("/update")
    public boolean updateHandle(@RequestBody Pets pets) {
        return service.modifyPets(pets);
    }

    // 根据id查询
    @GetMapping("/get/{id}")
    public Pets getHandle(@PathVariable("id") int id) {
        return service.getPetsById(id);
    }

    // 查询列表
    @GetMapping("/list")
    public List<Pets> listHandle() {
        return service.listAllPets();
    }
}
